package com.xzj.mybatis;

import com.xzj.mybatis.core.Resources;
import com.xzj.mybatis.core.SqlSession;
import com.xzj.mybatis.core.SqlSessionFactory;
import com.xzj.mybatis.core.SqlSessionFactoryBuilder;
import com.xzj.mybatis.entity.po.Blog;
import com.xzj.mybatis.mapper.BlogMapper;

import java.io.InputStream;
import java.util.List;

/**
 * @ProjectName: SpringDemo
 * @Package: com.xzj.mybatis
 * @ClassName: A
 * @Author: xzj
 * @Description:
 * @Date: 2022/7/21 10:04
 * @Version: 1.0
 */
public class MybatisBootstrap {

    public static void main(String[] args) {
        String resource = "application.yml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        BlogMapper mapper = sqlSession.getMapper(BlogMapper.class);
//        Blog blog = mapper.selectBlog(2);
//        Blog blog = new Blog();
//        blog.setUserName("abc");
//        blog.setPassword("mima");
//        int insert = mapper.insert(blog);
//
//        Blog blog1 = mapper.selectById(2);
//        System.out.println(blog1);
//        System.out.println(insert);
//        System.out.println(blog);

        Blog blog2 = new Blog();
        blog2.setUserName("1");
        List<Blog> blogs = mapper.selectAll(blog2);
        System.out.println(blogs);


    }

}
